package com.fitz.starter.config;

import com.fitz.core.config.FitzGatewayInitializer;
import com.fitz.core.filter.AbstractFilter;
import com.fitz.core.filter.GatewayBaseFilter;
import com.fitz.core.filter.SimpleRouteFilter;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.Map;

@Configuration
@EnableConfigurationProperties(GatewayProperties.class)
public class GatewayAutoConfig {

    @Bean
    public SimpleRouteFilter simpleRouteFilter(){
        return new SimpleRouteFilter();
    }


    @Configuration
    protected static class FilterAutoConfiguration{
        @Resource
        private Map<String, AbstractFilter> filters;

        @Bean
        public FitzGatewayInitializer initializer(){
            System.out.println("Initializer autoConfiguration >>>>>>>>>>");
            return new FitzGatewayInitializer(filters);
        }
    }

    @Bean
    public GatewayBaseFilter servletFilter(){
        return new GatewayBaseFilter();
    }
}
